package com.unionpay.mobile.android.pboctransaction.simapdu;

import android.content.Context;
import android.os.Handler;
import android.os.Handler.Callback;
import android.text.TextUtils;
import android.util.Log;
import com.unionpay.mobile.android.model.a;
import com.unionpay.mobile.android.pboctransaction.AppIdentification;
import com.unionpay.mobile.android.pboctransaction.d;
import com.unionpay.mobile.android.pboctransaction.e;
import com.unionpay.mobile.android.utils.h;
import com.unionpay.mobile.android.utils.i;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
import org.simalliance.openmobileapi.Channel;
import org.simalliance.openmobileapi.Reader;
import org.simalliance.openmobileapi.SEService;
import org.simalliance.openmobileapi.Session;

public final class b
  implements com.unionpay.mobile.android.pboctransaction.c
{
  private static b d = new b();
  private SEService a = null;
  private Channel[] b = new Channel[3];
  private com.unionpay.mobile.android.pboctransaction.b c;
  private Handler.Callback e = new c(this);
  private Handler f = new Handler(this.e);

  private String a(String paramString, int paramInt)
    throws a.a
  {
    Object localObject1 = null;
    if (paramString == null)
      return localObject1;
    while (true)
    {
      while (true)
      {
        String str1;
        try
        {
          h.a("plugin-sim", "====>" + paramString);
          str1 = paramString.toUpperCase(Locale.CHINA);
          if (paramInt > this.b.length)
            paramInt = 0;
          if ((str1.startsWith("00A40400")) || (str1.startsWith("01A40400")))
            break label272;
          boolean bool = str1.startsWith("02A40400");
          i = 0;
          if (bool)
            break label272;
          if (i != 0)
          {
            a(paramInt);
            localObject1 = b(e.a(str1.substring(10, 10 + 2 * (16 * Integer.parseInt(str1.substring(8, 9), 16) + Integer.parseInt(str1.substring(9, 10), 16)))), paramInt);
            if (!TextUtils.isEmpty((CharSequence)localObject1))
              break;
            h.c("plugin-sim", " writeApdu openchannel exception!!!");
            throw new a.a();
          }
        }
        finally
        {
        }
        try
        {
          byte[] arrayOfByte = e.a(str1);
          localObject1 = null;
          if (arrayOfByte != null)
          {
            String str2 = e.a(this.b[paramInt].transmit(arrayOfByte));
            localObject1 = str2;
          }
          h.a("plugin-sim", "<====" + (String)localObject1);
        }
        catch (IOException localIOException)
        {
          localIOException.printStackTrace();
          throw new a.a();
        }
        catch (Exception localException)
        {
          while (true)
          {
            localException.printStackTrace();
            localObject1 = null;
          }
        }
      }
      label272: int i = 1;
    }
  }

  private void a(int paramInt)
  {
    h.a("plugin-sim", "closeChannel(int) +++");
    if ((this.b[paramInt] != null) && (paramInt <= this.b.length));
    try
    {
      this.b[paramInt].close();
      this.b[paramInt] = null;
      h.a("plugin-sim", "closeChannel(int) ---");
      return;
    }
    catch (Exception localException)
    {
      while (true)
      {
        localException.printStackTrace();
        h.a("plugin-sim", " mChannel[channel].close() exception!!!");
      }
    }
  }

  private String b(byte[] paramArrayOfByte, int paramInt)
  {
    try
    {
      Reader[] arrayOfReader = this.a.getReaders();
      if (arrayOfReader.length > 0)
      {
        Channel localChannel = arrayOfReader[0].openSession().openLogicalChannel(paramArrayOfByte);
        if (localChannel != null)
        {
          this.b[paramInt] = localChannel;
          byte[] arrayOfByte = localChannel.getSelectResponse();
          String str = e.a(arrayOfByte, arrayOfByte.length);
          return str;
        }
      }
    }
    catch (Throwable localThrowable)
    {
      localThrowable.printStackTrace();
    }
    return "";
  }

  public static b e()
  {
    try
    {
      b localb = d;
      return localb;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public final ArrayList<com.unionpay.mobile.android.model.c> a(d paramd)
  {
    h.c("plugin-sim", " SIMEngine.readList() +++");
    try
    {
      ArrayList localArrayList1 = new ArrayList(1);
      String str1 = paramd.a("A0000003330101");
      h.c("plugin-sim", "full AID:" + str1);
      if (str1 != null)
      {
        if (str1.length() < 16)
          return null;
        localArrayList1.add(new AppIdentification(str1, null));
        ArrayList localArrayList3;
        if (localArrayList1.size() > 0)
        {
          localArrayList3 = new ArrayList();
          Throwable localThrowable1;
          try
          {
            Iterator localIterator = localArrayList1.iterator();
            while (localIterator.hasNext())
            {
              AppIdentification localAppIdentification = (AppIdentification)localIterator.next();
              if (!"06".equalsIgnoreCase(localAppIdentification.b()))
              {
                String str2 = e.c(paramd.a(localAppIdentification));
                h.a("nfcphone", " cardNumber=" + str2);
                if ((str2 != null) && (str2.length() > 0))
                {
                  localArrayList3.add(new a(16, localAppIdentification.a(), "", str2, 1));
                  h.a("nfcphone", " valid Number= " + str2);
                }
              }
            }
          }
          catch (Throwable localThrowable3)
          {
            localThrowable1 = localThrowable3;
            localArrayList2 = localArrayList3;
          }
          Log.e("plugin-sim", " SimEngine Exception = " + localThrowable1.getMessage());
        }
        while (true)
        {
          h.c("plugin-sim", " SIMEngine.readList() ---");
          return localArrayList2;
          localArrayList2 = localArrayList3;
          continue;
          Log.e("plugin-sim", " SIMEngine --- there has no PBOC aids!!!");
          localArrayList2 = null;
        }
      }
    }
    catch (Throwable localThrowable2)
    {
      while (true)
        ArrayList localArrayList2 = null;
    }
    return null;
  }

  public final void a()
  {
    h.c("plugin-sim", "SIMEngine.destroy() +++ ");
    h.c("plugin-sim", " mSEService = " + this.a);
    d();
    if ((this.a != null) && (this.a.isConnected()))
    {
      h.a("TAG", " mSEService.isConnected() = " + this.a.isConnected());
      h.c("plugin-sim", " mSEService.shutdown() ");
      this.a.shutdown();
    }
    h.c("plugin-sim", "SIMEngine.destroy() --- ");
  }

  public final void a(com.unionpay.mobile.android.pboctransaction.b paramb, Context paramContext)
  {
    this.c = paramb;
    try
    {
      new i();
      if ((i.a() != null) && (i.a().isConnected()))
      {
        this.a = i.a();
        this.f.sendEmptyMessage(1);
        return;
      }
      this.f.sendEmptyMessage(2);
      return;
    }
    catch (Throwable localThrowable)
    {
      localThrowable.printStackTrace();
      Log.e("plugin-sim", " service ERROR!!!");
      this.f.sendEmptyMessage(2);
    }
  }

  public final byte[] a(byte[] paramArrayOfByte, int paramInt)
  {
    h.c("plugin-sim", " SIMEngine.sendApdu() +++");
    try
    {
      byte[] arrayOfByte2 = e.a(a(e.a(paramArrayOfByte, paramArrayOfByte.length), paramInt));
      arrayOfByte1 = arrayOfByte2;
      h.c("plugin-sim", " SIMEngine.sendApdu() ---");
      return arrayOfByte1;
    }
    catch (a.a locala)
    {
      while (true)
      {
        locala.printStackTrace();
        h.c("plugin-sim", " " + locala.getMessage());
        byte[] arrayOfByte1 = null;
      }
    }
  }

  public final void b()
  {
  }

  public final void c()
  {
    d();
  }

  public final void d()
  {
    h.a("plugin-sim", "closeChannels() +++");
    for (int i = 0; i < this.b.length; i++)
      a(i);
    h.a("plugin-sim", "closeChannels() ---");
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.unionpay.mobile.android.pboctransaction.simapdu.b
 * JD-Core Version:    0.6.2
 */